﻿using HCMS.CommonDtos;
using HCMS.Entities.Base;
using HCMS.IRepositories.Base;
using HCMS.IServices.Base;
using HCMS.Repositories.Base;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace HCMS.Services.Base
{
    /// <summary>
    /// 系统 配置 应用服务
    /// </summary>
    public class SystemConfigAppService : CommonAppService<BaseDbContext, SystemConfig>, ISystemConfigAppService
    {
        private readonly IRepository<SystemConfig> baseSystemConfigRepository;
        private readonly ISystemConfigRepository systemConfigRepository;

        public SystemConfigAppService(
            IRepository<SystemConfig> baseSystemConfigRepository,
            ISystemConfigRepository systemConfigRepository
            ) : base(baseSystemConfigRepository)
        {
            this.baseSystemConfigRepository = baseSystemConfigRepository;
            this.systemConfigRepository = systemConfigRepository;
        }

        /// <summary>
        /// 管理 列表
        /// </summary>
        /// <param name="searchArgs">搜索 参数</param>
        /// <param name="pager">分页 参数</param>
        /// <returns></returns>
        public async Task<ListPagerDto<object>> ManageList(SearchArgsDto searchArgs, PagerArgsDto pager)
        {
            var systemConfig = await systemConfigRepository.ManageList(searchArgs, pager);

            var result = new ListPagerDto<object>();
            result.PagerInfo = systemConfig.PagerInfo;

            var data = new List<object>();
            foreach (var item in systemConfig.Data)
            {
                data.Add(new
                {
                    id = item.Id,
                    createTime = item.CreateTime,
                    createUser = item.CreateUser,
                    updateTime = item.UpdateTime,
                    updateUser = item.UpdateUser,
                    status = item.Status,
                    title = item.Title,
                    configKey = item.ConfigKey,
                    configValue = item.ConfigValue
                });
            }

            result.Data = data;

            return result;
        }
    }
}
